﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;


namespace Jemgine.MapEditor.Operations
{
	internal class AssignTexture : Operation
	{
		Engine.Selection _Owner;
        Data.TexturedObject Owner;
        String OldValue;

        internal AssignTexture(Engine.Selection Owner)
        {
            _Owner = Owner;
        }

        internal override ReturnCode Do(EditorState ES)
        {
            Owner = ES.GetSelectionObject(_Owner) as Data.TexturedObject;
            if (Owner != null)
            {
                OldValue = Owner.Texture;
                String NewValue = Jemgine.Data.ResourceEditor.InvokeResourceBrowser(ContentManifestExtensions.ContentType.Texture, 
                    OldValue);
                Owner.SetTexture(NewValue, ES.GetTexture(NewValue));
                return ReturnCode.AddToUndoStack;
            }

            return ReturnCode.DoNotAddToUndoStack;
        }

		internal override void Undo(EditorState ES)
		{
            Owner.SetTexture(OldValue, ES.GetTexture(OldValue));
		}



	}
}
